package oppsa.view;

import java.util.ArrayList;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import oppsa.controller.SSComponent;
import oppsa.controller.SubSystem;
import oppsa.controller.Translate;
import oppsa.model.SSComponentDB;
import oppsa.model.SubsystemDB;

public class JTreeSystem {
	
	private Translate t = new Translate();
	
	public DefaultTreeModel getNode() {
		
		SSComponentDB listComponent = new SSComponentDB();
		SubsystemDB listSubsystem = new SubsystemDB();
		listSubsystem.select();
		listComponent.select();
		
		DefaultMutableTreeNode systemNode = new DefaultMutableTreeNode(t.getLocalizedText("lblSubSystem"));
		
		
		
		for (SubSystem subSystem : listSubsystem.getFullList())
		{
			
			DefaultMutableTreeNode nodeSubSystem = new DefaultMutableTreeNode(subSystem.getSubsystemName());
			systemNode.add(nodeSubSystem);
			ArrayList<SSComponent> listSSComponent = new ArrayList<SSComponent>();
			listSSComponent = listComponent.getComponentInSubSystem(subSystem.getSequence());
			for (SSComponent component : listSSComponent)
			{
				DefaultMutableTreeNode nodeComponent = new DefaultMutableTreeNode(component.getSsComponentName());
				nodeSubSystem.add(nodeComponent);			
			}
		} 

		return new DefaultTreeModel(systemNode);

	}
}
